// Pages/needsSend/needsSend
Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeData: [{ 'index': '1', 'typeName': '手机' }, { 'index': '2', 'typeName': '数码' }, { 'index': '3', 'typeName': '电脑' }, { 'index': '4', 'typeName': '办公' }, { 'index': '5', 'typeName': '男装' }, { 'index': '6', 'typeName': '女装' }, { 'index': '7', 'typeName': '美妆' }, { 'index': '8', 'typeName': '鞋子' }, { 'index': '9', 'typeName': '箱包' }, { 'index': '10', 'typeName': '书籍' }, { 'index': '11', 'typeName': '其他' },],

    newold:[1,2,3,4,5,6,7,8,9,10],/**新旧程度 */
    newindex:0,
    index:10,

    /**获取可物物交换的id */
    info: [{
      "sellId": -1,
      "thingName": "下拉选择"
    },],
    sellindex:0,
    sellId:0,

    thingName:'',
    descri:'',
    pricceLow:'',/**价格 */
    priceHigh:'',
    exchangeable:1,
    thingToThingId:'',
    type:''
      },

  /**
   * 生命周期函数--监听页面加载
   */



  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getInfoChange();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  ss: function (e) {/**设置商品分类 */
    this.setData({
      index: e.detail.value,
      // typeId: e.describe.value + 1
    })
  },
  changenewold:function(e){/**新旧程度 */
    
    this.setData({
      newindex: e.detail.value,

    })
  },
  /**物物交换选择 */
  infochange: function (e) {/**交换物品链接分类 */
    
    this.setData({
      sellindex: e.detail.value,
      sellId: this.data.info,
        
    })
    console.log(this.data.info[this.data.sellindex].sellId)
  },
  getInfoChange(){/* */
    var that=this;
    var token = wx.getStorageSync("token");
    wx.request({
      url: 'http://47.103.21.65:5645/require/getChangeProducts',

      method: "POST",

      data: {  //参数传递

      },
      header: { //设置请求头
        'content-type': 'application/x-www-form-urlencoded',// 默认值//header:{...}用啥设置啥，
        'token': token
      },
      success: function (res) {
          console.log(res)
        var list = that.data.info.concat(res.data.data.info);//两个数组拼接
       that.setData({
         info:list
       })
      },
      fail: function (error) { //请求失败
        console.log(error);

      }
    })
  },

  setThingsName:function(e){/**设置名称 */
    this.setData({
      thingName:e.detail.value
    })
  },
  setdescribe:function(e){
    /**描述 */
    this.setData({
        descri:e.detail.value
    })
  },
  setPricelo:function(e){
    /**设置低价 */
    this.setData({
      pricceLow:e.detail.value
    })
  },
  setPricehi:function(e){
    /**设置高价 */
    this.setData({
      priceHigh: e.detail.value
    })
  },
  setchangeable:function(e){
    var that = this;
    that.setData({
      exchangeable: e.detail.value
    })
    console.log(that.data.exchangeable)
  },
  submit:function(){
    /**提交操作 */
    console.log(1231231231231)
    var token = wx.getStorageSync("token");
    var that=this;
    console.log(that.data.info[that.data.sellindex].sellId)
    var exc = parseInt(that.data.exchangeable);
    var thingtot = parseInt(that.data.info[that.data.sellindex].sellId);
    var ty = parseInt(that.data.index) + 1;
    console.log(thingtot)
    console.log(exc)

    console.log(ty)
    console.log(exc+"8989898989999999999999")
    wx.request({
      url: 'http://47.103.21.65:5645/require/postRequire',
      method: "POST",
      
      data: {  //参数传递
        thingName:that.data.thingName,
        newOld: that.data.newindex+1,
        descri: that.data.descri,
        pricceLow:that.data.pricceLow,
        priceHigh:that.data.priceHigh,
        exchangeable: exc ,
        thingToThingId:exc==1?thingtot:'' ,/**拿到商品id */
        type: ty
      },
      header: { //设置请求头
        'content-type': 'application/x-www-form-urlencoded',// 默认值//header:{...}用啥设置啥，
        'token': token
      },
      success: function (res) {
       console.log(res)
       wx.showToast({
         title: '发布成功',
         icon:'success'
       })
       setTimeout(function(){
          wx.navigateBack({
            
          })
       },1000)
       
      },
      fail: function (error) { //请求失败
        console.log(error);

      }
    })
  }
})